package com.hushi.test;

import com.hushi.config.Springcfg;
import com.hushi.impl.CustomerServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * IOC入门程序
 */

public class Demo1 {
    /**
     * 测试 @Configurable
     */
    @Test
    public void test1(){
        //@Configuration注解的spring容器加载方式
        ApplicationContext ac = new AnnotationConfigApplicationContext(Springcfg.class);
    }

    /**
     * 测试 @PropertySource
     */
    @Test
    public void test2(){
        //@Configuration注解的spring容器加载方式
        ApplicationContext ac = new AnnotationConfigApplicationContext(Springcfg.class);
        CustomerServiceImpl customerService = (CustomerServiceImpl) ac.getBean("customerServiceImpl");
        customerService.save();
    }

    /**
     * 测试
     */
    @Test
    public void test3(){
        //@Configuration注解的spring容器加载方式
        ApplicationContext ac = new AnnotationConfigApplicationContext(Springcfg.class);
        CustomerServiceImpl customerService = (CustomerServiceImpl) ac.getBean("customerServiceImpl");
        customerService.save1();
    }

    /**
     * 测试 @Import
     */
    @Test
    public void test4(){
        //@Configuration注解的spring容器加载方式
        ApplicationContext ac = new AnnotationConfigApplicationContext(Springcfg.class);
        CustomerServiceImpl customerServiceImpl = (CustomerServiceImpl) ac.getBean("customerServiceImpl");
        customerServiceImpl.getCustomerDao();
    }

    /**
     * 测试 @Bean
     */
    @Test
    public void test5(){
        //@Configuration注解的spring容器加载方式
        ApplicationContext ac = new AnnotationConfigApplicationContext(Springcfg.class);
        CustomerServiceImpl customerServiceImpl = (CustomerServiceImpl) ac.getBean("customerServiceImpl");
        System.out.println(customerServiceImpl);
    }
}